package com.liugai.lgeachday.request;

public class Response {
    private int code;
    private String msg;
    private Object data;

    public Response(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /*请求成功*/
    public static Response successResponse(String msg, Object data) {
        return new Response(200, msg, data);
    }

    /*请求失败*/
    public static Response failedResponse(String msg) {
        return new Response(200501, msg, null);
    }

    /*参数为空*/
    public static Response emptyParamResponse (String msg) {
        return new Response(200101, msg, null);
    }

    /*参数不匹配*/
    public static Response unMatchParamResponse (String msg) {
        return new Response(200102, msg, null);
    }

    /*查询结果为空*/
    public static Response emptyResultResponse(String msg) {
        return new Response(200401, msg, null);
    }

    /*数据已存在*/
    public static Response existMutableResponse(String msg) {
        return new Response(200301, msg, null);
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        if (msg == null) {
            msg = StatusMessage.getHttpStatusMsg(code);
        }
        return msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Response{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
